#include "alertlist.h"

AlertList::AlertList()
{
}
void AlertList::addAlert(Alert alert)
{
    alertList.push_back(alert);
}

void AlertList::deleteAlert(Alert r)
{
    for(unsigned int i=0;i<alertList.size();++i)
    {
        if(alertList[i].getnameid() == r.getnameid())
        {
            alertList.erase(alertList.begin()+i);
            break;
        }
    }
}

void AlertList::modifyAlert(Alert oldAlert, Alert newAlert)
{
    //find the old Alert
    for (unsigned int i=0;i<alertList.size();i++)
    {
        if(alertList[i].getnameid()==oldAlert.getnameid())
        {
            alertList[i] = newAlert;
            break;
        }
    }

}
vector<Alert> AlertList::getAlertList(void)
{
    return alertList;
}
void AlertList::clearList()
{
    alertList.clear();
}
int AlertList::size(){
    return alertList.size();
}
void AlertList::printList(){
    int i = 0;
    for(i = 0;i <alertList.size();i++){
        alertList[i].print();
    }
}
Alert AlertList::operator [](int index){
    return alertList[index];
}
void AlertList::operator =(AlertList alertList){
    this->alertList = alertList.getAlertList();
}
/*
vector<Alert> AlertList::searchAlert(string input, string category, string field,
                                        QDateTime fromTime, QDateTime toTime, double fromPrice, double toPrice){
    int i = 0;
    vector<Alert> results;
    if(field == "All Fields"){
        if(category == "All")
            for(i = 0; i < alertList.size(); i++){
              if(alertList[i].getinfo().find(input) != string::npos || alertList[i].getname().find(input) != string::npos ||
                      (alertList[i].getamount() < toPrice && alertList[i].getamount() > fromPrice) ||
                      (alertList[i].getdatetime() < toTime && alertList[i].getdatetime() > fromTime))
                  results.push_back(alertList[i]);
            }
        else{
            for(i = 0; i < alertList.size(); i++){
              if(alertList[i].getcategory() == category)
                  if(alertList[i].getinfo().find(input) != string::npos || alertList[i].getname().find(input) != string::npos||
                          (alertList[i].getamount() < toPrice && alertList[i].getamount() > fromPrice) ||
                          (alertList[i].getdatetime() < toTime && alertList[i].getdatetime() > fromTime))
                      results.push_back(alertList[i]);
            }
        }
     }
     else if(field == "Name"){
        if(category == "All"){
            for(i = 0; i < alertList.size(); i++)
               if(alertList[i].getname().find(input) != string::npos)
                   results.push_back(alertList[i]);
        }
        else{
            for(i = 0; i < alertList.size(); i++)
                  if(alertList[i].getcategory() == category)
                        if(alertList[i].getname().find(input) != string::npos)
                              results.push_back(alertList[i]);
        }
     }
     else if(field == "Description"){
        if(category == "All"){
            for(i = 0; i < alertList.size(); i++)
                    if(alertList[i].getinfo().find(input) != string::npos)
                       results.push_back(alertList[i]);
         }
        else{
            for(i = 0; i < alertList.size(); i++)
                if(alertList[i].getcategory() == category)
                    if(alertList[i].getinfo().find(input) != string::npos)
                        results.push_back(alertList[i]);
        }
    }
    else if(field == "Price Range"){
        if(category == "All"){
            for(i = 0; i < alertList.size(); i++)
                    if(alertList[i].getamount() < toPrice && alertList[i].getamount() > fromPrice)
                       results.push_back(alertList[i]);
         }
        else{
            for(i = 0; i < alertList.size(); i++)
                if(alertList[i].getcategory() == category)
                    if(alertList[i].getamount() < toPrice && alertList[i].getamount() > fromPrice)
                        results.push_back(alertList[i]);
        }
    }
    else if(field == "Date Range"){
        if(category == "All"){
            for(i = 0; i < alertList.size(); i++)
                    if(alertList[i].getdatetime() < toTime && alertList[i].getdatetime() > fromTime)
                       results.push_back(alertList[i]);
         }
        else{
            for(i = 0; i < alertList.size(); i++)
                if(alertList[i].getcategory() == category)
                    if(alertList[i].getdatetime() < toTime && alertList[i].getdatetime() > fromTime)
                        results.push_back(alertList[i]);
        }
    }
    return results;
}
*/
